package com.dianping.cat.home.router.transform;

import com.dianping.cat.home.router.IEntity;
import com.dianping.cat.home.router.IVisitor;
import com.dianping.cat.home.router.entity.DefaultServer;
import com.dianping.cat.home.router.entity.Domain;
import com.dianping.cat.home.router.entity.Group;
import com.dianping.cat.home.router.entity.GroupServer;
import com.dianping.cat.home.router.entity.Network;
import com.dianping.cat.home.router.entity.NetworkPolicy;
import com.dianping.cat.home.router.entity.RouterConfig;
import com.dianping.cat.home.router.entity.Server;
import com.dianping.cat.home.router.entity.ServerGroup;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  19 */   private Stack<Object> m_objs = new Stack();
  
  private RouterConfig m_routerConfig;

  
  public DefaultMerger() {}
  
  public DefaultMerger(RouterConfig routerConfig) {
/*  27 */     this.m_routerConfig = routerConfig;
/*  28 */     this.m_objs.push(routerConfig);
  }

  
  public RouterConfig getRouterConfig() { return this.m_routerConfig; }



  protected Stack<Object> getObjects() { return this.m_objs; }

  
  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  40 */     this.m_objs.push(to);
/*  41 */     from.accept(this);
/*  42 */     this.m_objs.pop();
  }

  
/*  46 */   protected void mergeDefaultServer(DefaultServer to, DefaultServer from) { to.mergeAttributes(from); }



/*  50 */   protected void mergeDomain(Domain to, Domain from) { to.mergeAttributes(from); }



/*  54 */   protected void mergeGroup(Group to, Group from) { to.mergeAttributes(from); }



/*  58 */   protected void mergeGroupServer(GroupServer to, GroupServer from) { to.mergeAttributes(from); }



/*  62 */   protected void mergeNetwork(Network to, Network from) { to.mergeAttributes(from); }



/*  66 */   protected void mergeNetworkPolicy(NetworkPolicy to, NetworkPolicy from) { to.mergeAttributes(from); }



/*  70 */   protected void mergeRouterConfig(RouterConfig to, RouterConfig from) { to.mergeAttributes(from); }



/*  74 */   protected void mergeServer(Server to, Server from) { to.mergeAttributes(from); }



  protected void mergeServerGroup(ServerGroup to, ServerGroup from) { to.mergeAttributes(from); }


  
  public void visitDefaultServer(DefaultServer from) {
/*  83 */     DefaultServer to = (DefaultServer)this.m_objs.peek();

/*  85 */     mergeDefaultServer(to, from);
/*  86 */     visitDefaultServerChildren(to, from);
  }

  
  protected void visitDefaultServerChildren(DefaultServer to, DefaultServer from) {}

  
  public void visitDomain(Domain from) {
/*  94 */     Domain to = (Domain)this.m_objs.peek();

/*  96 */     mergeDomain(to, from);
/*  97 */     visitDomainChildren(to, from);
  }
  
  protected void visitDomainChildren(Domain to, Domain from) {
/* 101 */     for (Group source : from.getGroups().values()) {
/* 102 */       Group target = to.findGroup(source.getId());

/* 104 */       if (target == null) {
/* 105 */         target = new Group(source.getId());
/* 106 */         to.addGroup(target);
      }
      
/* 109 */       this.m_objs.push(target);
/* 110 */       source.accept(this);
/* 111 */       this.m_objs.pop();
    }
  }

  
  public void visitGroup(Group from) {
/* 117 */     Group to = (Group)this.m_objs.peek();

/* 119 */     mergeGroup(to, from);
/* 120 */     visitGroupChildren(to, from);
  }
  
  protected void visitGroupChildren(Group to, Group from) {
/* 124 */     for (Server source : from.getServers()) {
/* 125 */       Server target = null;

/* 127 */       if (target == null) {
/* 128 */         target = new Server();
/* 129 */         to.addServer(target);
      }
      
/* 132 */       this.m_objs.push(target);
/* 133 */       source.accept(this);
/* 134 */       this.m_objs.pop();
    }
  }

  
  public void visitGroupServer(GroupServer from) {
/* 140 */     GroupServer to = (GroupServer)this.m_objs.peek();

/* 142 */     mergeGroupServer(to, from);
/* 143 */     visitGroupServerChildren(to, from);
  }

  
  protected void visitGroupServerChildren(GroupServer to, GroupServer from) {}

  
  public void visitNetwork(Network from) {
/* 151 */     Network to = (Network)this.m_objs.peek();

/* 153 */     mergeNetwork(to, from);
/* 154 */     visitNetworkChildren(to, from);
  }

  
  protected void visitNetworkChildren(Network to, Network from) {}

  
  public void visitNetworkPolicy(NetworkPolicy from) {
/* 162 */     NetworkPolicy to = (NetworkPolicy)this.m_objs.peek();

/* 164 */     mergeNetworkPolicy(to, from);
/* 165 */     visitNetworkPolicyChildren(to, from);
  }
  
  protected void visitNetworkPolicyChildren(NetworkPolicy to, NetworkPolicy from) {
/* 169 */     for (Network source : from.getNetworks().values()) {
/* 170 */       Network target = to.findNetwork(source.getId());

/* 172 */       if (target == null) {
/* 173 */         target = new Network(source.getId());
/* 174 */         to.addNetwork(target);
      }
      
/* 177 */       this.m_objs.push(target);
/* 178 */       source.accept(this);
/* 179 */       this.m_objs.pop();
    }
  }

  
  public void visitRouterConfig(RouterConfig from) {
/* 185 */     RouterConfig to = (RouterConfig)this.m_objs.peek();

/* 187 */     mergeRouterConfig(to, from);
/* 188 */     visitRouterConfigChildren(to, from);
  }
  
  protected void visitRouterConfigChildren(RouterConfig to, RouterConfig from) {
/* 192 */     for (DefaultServer source : from.getDefaultServers().values()) {
/* 193 */       DefaultServer target = to.findDefaultServer(source.getId());

/* 195 */       if (target == null) {
/* 196 */         target = new DefaultServer(source.getId());
/* 197 */         to.addDefaultServer(target);
      }
      
/* 200 */       this.m_objs.push(target);
/* 201 */       source.accept(this);
/* 202 */       this.m_objs.pop();
    }
    
/* 205 */     for (NetworkPolicy source : from.getNetworkPolicies().values()) {
/* 206 */       NetworkPolicy target = to.findNetworkPolicy(source.getId());

/* 208 */       if (target == null) {
/* 209 */         target = new NetworkPolicy(source.getId());
/* 210 */         to.addNetworkPolicy(target);
      }
      
/* 213 */       this.m_objs.push(target);
/* 214 */       source.accept(this);
/* 215 */       this.m_objs.pop();
    }
    
/* 218 */     for (ServerGroup source : from.getServerGroups().values()) {
/* 219 */       ServerGroup target = to.findServerGroup(source.getId());

/* 221 */       if (target == null) {
/* 222 */         target = new ServerGroup(source.getId());
/* 223 */         to.addServerGroup(target);
      }
      
/* 226 */       this.m_objs.push(target);
/* 227 */       source.accept(this);
/* 228 */       this.m_objs.pop();
    }
    
/* 231 */     for (Domain source : from.getDomains().values()) {
/* 232 */       Domain target = to.findDomain(source.getId());

/* 234 */       if (target == null) {
/* 235 */         target = new Domain(source.getId());
/* 236 */         to.addDomain(target);
      }
      
/* 239 */       this.m_objs.push(target);
/* 240 */       source.accept(this);
/* 241 */       this.m_objs.pop();
    }
  }

  
  public void visitServer(Server from) {
/* 247 */     Server to = (Server)this.m_objs.peek();

/* 249 */     mergeServer(to, from);
/* 250 */     visitServerChildren(to, from);
  }

  
  protected void visitServerChildren(Server to, Server from) {}

  
  public void visitServerGroup(ServerGroup from) {
/* 258 */     ServerGroup to = (ServerGroup)this.m_objs.peek();

/* 260 */     mergeServerGroup(to, from);
/* 261 */     visitServerGroupChildren(to, from);
  }
  
  protected void visitServerGroupChildren(ServerGroup to, ServerGroup from) {
/* 265 */     for (GroupServer source : from.getGroupServers().values()) {
/* 266 */       GroupServer target = to.findGroupServer(source.getId());

/* 268 */       if (target == null) {
/* 269 */         target = new GroupServer(source.getId());
/* 270 */         to.addGroupServer(target);
      }
      
/* 273 */       this.m_objs.push(target);
/* 274 */       source.accept(this);
/* 275 */       this.m_objs.pop();
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/classes/!/com/dianping/cat/home/router/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */